// pages/teacher/homework/homework.js
Page({
  data: {
    currentTab: 0,
    tabs: ['待批改', '已批改', '全部作业'],
    // 待批改作业
    pendingHomework: [
      {
        id: 1,
        studentName: '张同学',
        studentAvatar: '/images/avatar1.jpg',
        courseName: '微信小程序开发实战',
        homeworkTitle: '第一章课后练习',
        submitTime: '2025-10-28 10:30',
        score: null,
        totalScore: 100
      },
      {
        id: 2,
        studentName: '李同学',
        studentAvatar: '/images/avatar2.jpg',
        courseName: 'Python数据分析与挖掘',
        homeworkTitle: '第二章综合练习',
        submitTime: '2025-10-27 15:20',
        score: null,
        totalScore: 100
      }
    ],
    // 已批改作业
    gradedHomework: [
      {
        id: 3,
        studentName: '王同学',
        studentAvatar: '/images/avatar3.jpg',
        courseName: '微信小程序开发实战',
        homeworkTitle: '第一章课后练习',
        submitTime: '2025-10-26 20:15',
        gradeTime: '2025-10-27 09:00',
        score: 85,
        totalScore: 100
      }
    ],
    // 作业模板列表
    homeworkTemplates: [
      {
        id: 1,
        title: '第一章课后练习',
        courseName: '微信小程序开发实战',
        questionCount: 10,
        totalScore: 100,
        submitCount: 15,
        createTime: '2025-10-15 10:00'
      },
      {
        id: 2,
        title: '第二章综合练习',
        courseName: 'Python数据分析与挖掘',
        questionCount: 15,
        totalScore: 100,
        submitCount: 12,
        createTime: '2025-10-18 14:30'
      }
    ]
  },
  onLoad() {},
  switchTab(e) {
    this.setData({
      currentTab: e.currentTarget.dataset.index
    })
  },
  createHomework() {
    wx.showModal({
      title: '创建作业',
      content: '跳转到作业编辑页面',
      showCancel: false,
      success: () => {
        wx.showToast({
          title: '功能开发中',
          icon: 'none'
        })
      }
    })
  },
  gradeHomework(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '批改作业',
      editable: true,
      placeholderText: '请输入分数(0-100)',
      success: (res) => {
        if (res.confirm) {
          const score = parseFloat(res.content)
          if (isNaN(score) || score < 0 || score > 100) {
            wx.showToast({
              title: '请输入有效分数',
              icon: 'none'
            })
            return
          }
          wx.showToast({
            title: `评分成功: ${score}分`,
            icon: 'success'
          })
        }
      }
    })
  },
  viewHomework(e) {
    const id = e.currentTarget.dataset.id
    wx.showToast({
      title: '查看作业详情',
      icon: 'none'
    })
  },
  editTemplate(e) {
    const id = e.currentTarget.dataset.id
    wx.showToast({
      title: '编辑作业模板',
      icon: 'none'
    })
  },
  deleteTemplate(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '确认删除',
      content: '删除后将无法恢复，确定删除此作业模板吗？',
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '删除成功',
            icon: 'success'
          })
        }
      }
    })
  }
})
